package com.zhf.douyinvideo.fragment

import android.os.Parcelable
import android.support.v4.app.Fragment
import android.support.v4.app.FragmentManager
import android.support.v4.app.FragmentStatePagerAdapter
import android.support.v4.view.ViewPager
import android.view.View
import android.view.ViewGroup
import com.zhf.douyinvideo.R
import com.zhf.douyinvideo.base.BaseFragment

/**
 * 首页
 * Created by zhf on 2019/9/5 14:22
 */
class HomeFragment : BaseFragment() {

    private val fragmentList: List<Fragment> = listOf<Fragment>(VideoLeftFragment(), CourseFragment("测试"))

    private lateinit var viewPager: ViewPager
    
    override val contentLayoutId: Int
        get() = R.layout.fragment_home
    
 
    
    override fun initWidget(root: View) {
        super.initWidget(root)
        viewPager = root.findViewById(R.id.viewPager)
    }


    override fun initData() {
        super.initData()

        var adapter = HomeAdapter(childFragmentManager, fragmentList)
        viewPager.adapter = adapter
        viewPager.currentItem = 0
    }


    /**
    * 首页 adapter
    * Created by zhf on 2019/9/5 14:29
    */
    class HomeAdapter(fm: FragmentManager, private val mlist: List<Fragment>) : FragmentStatePagerAdapter(fm) {

        override fun setPrimaryItem(container: ViewGroup, position: Int, `object`: Any) {
            super.setPrimaryItem(container, position, `object`)
        }

        override fun getItem(arg0: Int): Fragment {
            return mlist[arg0]
        }

        override fun getCount(): Int {
            return mlist.size
        }

        override fun restoreState(state: Parcelable?, loader: ClassLoader?) {
            // super.restoreState(state, loader)
        }
    }


}
